package com.westa.smallshop.data;

import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

/**
 * Created by Dune on 16/3/9.
 */
public class HttpError implements Parcelable {

    public static final Creator<HttpError> CREATOR = new Creator<HttpError>() {
        @Override
        public HttpError createFromParcel(Parcel source) {
            return new HttpError(source);
        }

        @Override
        public HttpError[] newArray(int size) {
            return new HttpError[size];
        }
    };
    private String status;
    @NonNull
    private String content;
    private String detail;

    public HttpError() {
    }


    public HttpError(@NonNull String content) {
        this.content = content;
    }

    protected HttpError(Parcel in) {
        this.status = in.readString();
        this.content = in.readString();
        this.detail = in.readString();
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    @NonNull
    public String getContent() {
        return content;
    }

    public void setContent(@Nullable String content) {
        this.content = content;
    }

    public boolean isNotFound() {

        return "not found".equals(content);
    }

    public boolean isNotAuth() {

        return "not auth".equals(content);
    }

    public boolean isNotAuthLogin() {

        return "not login".equals(content) || "Invalid token.".equals(detail);
    }

    public boolean isNotAuthJw() {

        return "not verify".equals(content);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.status);
        dest.writeString(this.content);
        dest.writeString(this.detail);
    }
}
